//
//  GQToolLocation.m
//  GuQu
//
//  Created by HELIUM STAR on 15/5/13.
//  Copyright (c) 2015年 HELIUM STAR. All rights reserved.
//

#import "GQToolLocation.h"
#import <CoreLocation/CoreLocation.h>

@interface GQToolLocation () <CLLocationManagerDelegate>

@property (strong, nonatomic) CLLocationManager *mgr;
@property (assign, nonatomic) CLLocationCoordinate2D coordinate;

@end

@implementation GQToolLocation
singleton_implementation(GQToolLocation)

- (instancetype)init
{
    if (self = [super init]) {
        [self.mgr startUpdatingLocation];
    }
    return self;
}

- (void)getUserCurrentLocation
{
    NSLog(@"纬度：%f 经度：%f", _coordinate.latitude, _coordinate.longitude);
}

- (CLLocationManager *)mgr
{
    if (_mgr == nil) {
        _mgr = [[CLLocationManager alloc] init];
        _mgr.delegate = self;
        _mgr.distanceFilter = 100;
        _mgr.desiredAccuracy = kCLLocationAccuracyBestForNavigation;
    }
    return _mgr;
}

- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
{
    NSLog(@"2222");
    CLLocation *location = [locations lastObject];
    CLLocationCoordinate2D coordinate = location.coordinate;
    self.coordinate = coordinate;
    NSLog(@"纬度：%f 经度：%f", _coordinate.latitude, _coordinate.longitude);
    [manager stopUpdatingLocation];
}

@end
